//
//  PublicVM.m
//  Common
//
//  Created by guoshiqing on 2018/5/31.
//

#import "PublicVM.h"
#import <QiniuSDK.h>

@implementation PublicVM

// 【文件上传】获取token
- (void)getTokenFromServerWithFileType:(NSString *)type
{
    NSString *url = @"test";
    [self sendRequestWithUrl:url andParams:nil];
}

// 【文件上传】上传文件
- (void)sendFileWithToken:(NSString *)token andFilePath:(NSString *)filePath andKey:(NSString *)key withSuccessBlock:(StringBlock)success andProgressBlock:(ProgressBlock)progress andFailureBlock:(StringBlock)failure
{
    QNUploadManager *upManager = [[QNUploadManager alloc] init];
    QNUploadOption *uploadOption = [[QNUploadOption alloc] initWithMime:nil progressHandler:^(NSString *key, float percent) {
        if (progress) progress(percent);
    }
                                                                 params:nil
                                                               checkCrc:NO
                                                     cancellationSignal:nil];
    [upManager putFile:filePath key:key token:token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
        
//        NSString *ret = [resp objectForKey:@"ret"];
        long ret = [[resp objectForKey:@"ret"] floatValue];
//        if ([ret isEqualToString:@"0"]) {
        if (ret == 0) {
            if (success) return success(key);
        }
        else
        {
            if (failure) return failure(resp[@"msg"]);
        }
    }
                option:uploadOption];
}


// h5测试页面
- (void)requestH5Test
{
    NSString *url = @"test";
    [self sendRequestWithUrl:url andParams:nil];
}

// 版本更新检查
- (void)checkVersion:(NSString *)currentVersion
{
}
@end
